home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / games / mdlv13.zip / MDLSRC.ZIP / BG_GRX.H < prev    next >
C/C++ Source or Header  |  1996-07-09  |  15KB  |  475 lines

  1. //
  2. // this file by brian martin 1996
  3. // brian@phyast.pitt.edu
  4. //
  5. // this is part of the source for the MedDLe quake model viewer/editor
  6. //
  7.  
  8. /*typedefs */
  9. typedef unsigned char byte;
  10. typedef unsigned short int  word;
  11.  
  12. #define BG_CopyInt(src,dst,lng)  asm("movl  %0,%%esi \n"             \
  13.                             "movl  %1,%%edi \n"             \
  14.                             "movl  %2,%%ecx \n"             \
  15.                             "cld \n"                        \
  16.                             "rep \n"                        \
  17.                             "movsl (%%esi),(%%edi) \n"      \
  18.                             : :"g" (src),"g" (dst),"g" (lng) \
  19.                             :"esi","edi","ecx"              \
  20.                          )
  21. #define BG_SetInt(dst,lng,val)   asm("movl  %0,%%eax \n"             \
  22.                             "movl  %1,%%edi \n"             \
  23.                             "movl  %2,%%ecx \n"             \
  24.                             "cld \n"                        \
  25.                             "rep \n"                        \
  26.                             "stosl %%eax,(%%edi) \n"        \
  27.                             : :"g" (val),"g" (dst),"g" (lng) \
  28.                             :"eax","edi","ecx"              \
  29.                          )
  30. #define BG_SetChar(dst,lng,val)  asm("movb  %0,%%al  \n"             \
  31.                     "movl  %1,%%edi \n"             \
  32.                     "movl  %2,%%ecx \n"             \
  33.                     "cld \n"                        \
  34.                     "rep \n"                        \
  35.                         "stosb %%al,(%%edi) \n"         \
  36.                     : :"g" (val),"g" (dst),"g" (lng) \
  37.                     :"al","edi","ecx"               \
  38.                     )
  39.  
  40.  
  41. /*
  42. #define PACKED __attribute__((packed))
  43. typedef struct {
  44.     char VbeSignature[4] PACKED; //should be VESA when returned
  45.     short VbeVersion PACKED;    //0x0200=ver2; 0x0102=ver1.2
  46.     unsigned int OemStringPtr PACKED;  //real mode address
  47.     char Capabilities[4] PACKED;
  48.     unsigned int VideoModePtr PACKED;
  49.     short TotalMemory PACKED;
  50.     short OemSoftwareRev PACKED;
  51.     unsigned int OemVendorNamePtr PACKED;
  52.     unsigned int OemProductNamePtr PACKED;
  53.     unsigned int OemProductRevPtr PACKED;
  54.     char DataSpace[222] PACKED;
  55.     char OemData[256] PACKED;
  56.  
  57. } Vbe_InfoBlock;
  58. typedef struct {
  59.     //All VBE
  60.     short ModeAttributes PACKED;
  61.     char WinAAttributes PACKED;
  62.     char WinBAttributes PACKED;
  63.     short WinGranularity PACKED;
  64.     short WinSize PACKED;
  65.     short WinASegment PACKED;
  66.     short WinBSegment PACKED;
  67.     unsigned int WinFuncPtr PACKED;
  68.     short BytesPerScanLine PACKED;
  69.     // VBE1.2 and above
  70.     short XResolution PACKED;
  71.     short YResolution PACKED;
  72.     char XCharSize PACKED;
  73.     char YCharSize PACKED;
  74.     char NumberOfPlanes PACKED;
  75.     char BitsPerPixel PACKED;
  76.     char NumberOfBanks PACKED;
  77.     char MemoryModel PACKED;
  78.     char BankSize PACKED;
  79.     char NumberOfImagePages PACKED;
  80.     char Reserved PACKED;
  81.     // Direct Color Fields
  82.     char RedMaskSize PACKED;
  83.     char RedFieldPosition PACKED;
  84.     char GreenMaskSize PACKED;
  85.     char GreenFieldPosition PACKED;
  86.     char BlueMaskSize PACKED;
  87.     char BlueFieldPosition PACKED;
  88.     char RsvdMaskSize PACKED;
  89.     char RsvdFieldPosition PACKED;
  90.     char DirectColorModeInfo PACKED;
  91.     //VBE2.0 and above
  92.     unsigned int PhysBasePtr PACKED;
  93.     unsigned int OffScreenMemOffset PACKED;
  94.     short OffScreenMemSize PACKED;
  95.     char StringSpace[206] PACKED;
  96. } Vbe_ModeInfoBlock;
  97. */
  98.  
  99. typedef struct {
  100.   unsigned ModeAttributes;
  101.   unsigned granularity,startseg,farfunc;
  102.   short bscanline;
  103.   short XResolution;
  104.   short YResolution;
  105.   short charpixels;
  106.   unsigned bogus1,bogus2,bogus3,bogus4;
  107.   unsigned PhysBasePtr;
  108.   char bogus[228];
  109. } ModeInfoBlock;
  110.  
  111. int enum {
  112.     Std_320x200x256,
  113.     Vesa_320x200x256,
  114.     Vesa_360x200x256,
  115.     Vesa_320x240x256,
  116.     Vesa_360x240x256,
  117.     Vesa_320x400x256,
  118.     Vesa_360x400x256,
  119.     Vesa_640x350x256,
  120.     Vesa_640x400x256,
  121.     Vesa_640x480x256,
  122.     Vesa_800x600x256,
  123.     Vesa_1024x768x256
  124.     };
  125.  
  126.  
  127. typedef struct BG_ScreenCoor {
  128.   int x,y;
  129. };
  130. typedef struct BG_Polygon {
  131.   int x[48];
  132. };
  133.  
  134. //#define BG_X_SIZE         320
  135. //#define BG_Y_SIZE         200        /* number of pixels total */
  136. //#define BG_X_MAX          319
  137. //#define BG_Y_MAX          199        /* number of maximum pixel */
  138. //#define BG_X_CENTER       160
  139. //#define BG_Y_CENTER       100        /* middle of the screen */
  140. //#define BG_SCREEN_SIZE_CHAR 64000L       /* bytes in the colourmap */
  141. //#define BG_SCREEN_SIZE_INT  32000L       /* ints in the colourmap */
  142.  
  143. extern unsigned BG_ScreenWidth;
  144. extern unsigned BG_ScreenHeight;
  145. extern unsigned BG_ScreenSize;
  146.  
  147. extern unsigned char *BG_ScreenBuffer;
  148.  
  149. typedef struct xy_point {
  150.   int x,y;
  151. };
  152.  
  153. extern int *BG_Start;              /* polygon's */
  154. extern int *BG_End;                /* horizontal boundaries */
  155.  
  156. extern int BG_2DClipping;                          /* type of performed clipping */
  157. extern int BG_TempMinY,BG_TempMaxY;                          /* vertical boundaries */
  158.  
  159. extern int *BG_0Start;  /* contains [32-G_P].[G_P] values */
  160. extern int *BG_0End;    /* this thingie is to work faster */
  161. extern int *BG_1Start;  /* then multidimensional array */
  162. extern int *BG_1End;    /* hope so, */
  163. extern int *BG_2Start;
  164. extern int *BG_2End;
  165.  
  166. extern int *BG_RestStart[5];//={BG_0Start,BG_1Start,BG_2Start};
  167. extern int *BG_RestEnd[5];//={BG_0End,BG_1End,BG_2End};
  168.  
  169. // FUNCTIONS
  170.  
  171. extern void BG_GraphicsMode(char *drv, int mode );
  172. extern void BG_TextMode(void);
  173.  
  174. extern void BG_Blit(void);
  175. extern void BG_ClearScreen(byte color);
  176. //extern void BG_Text(word x, word y,char *string,register unsigned char color);
  177. extern void BG_Text(char *buff, int x, int y, int front, int back);
  178. extern void MDL_Text(word x,word y,char *string,register unsigned char color);
  179. extern void BG_PutPixel(word X, word Y, byte color );
  180. extern void BG_Line(int, int, int, int, int);
  181. extern void BG_WriteBMP(FILE *, unsigned char *pal, unsigned char *pic, unsigned w, unsigned h);
  182. extern void BG_ReadBMP(FILE *, unsigned char *pal, unsigned char *pic, unsigned *w, unsigned *h);
  183. extern void BG_SetPalette(byte *pal);
  184. extern void BG_OpenPalette(char *palname, unsigned char *pal);
  185.  
  186.  
  187. extern void BG_Clip (int , int , int , int );
  188.  
  189. extern int BG_LineXClip(int **,int **,int);
  190. extern int BG_LineYClip(int **,int **,int);
  191. extern int BG_PolyXClip(int *,int *,int, int);
  192.  
  193. extern void BG_ScanLine(int *edges,int dimension,int skip);
  194. extern void BG_InitBoarderArray(void);
  195. extern void BG_Poly(int *edges,int length, unsigned char color);
  196. extern void BG_GPoly(int *edges,int length);
  197. extern void BG_TPoly(int *x,int length,unsigned char color);
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206. /////////////////////////////////////////////////////////////////////////
  207. /////////////////////////////////////////////////////////////////////////
  208. #define T_LOG_FOCUS 8                       /* log perspective foreshortening */
  209. #define C_MAX_DIMENSIONS          5         /* dims in N-dimensional lines */
  210. #define C_Z_CLIPPING_MIN         10         /* where viewing plane is */
  211. #define C_X_CLIPPING_MIN          0         /* clipping cube */
  212. #define C_X_CLIPPING_MAX   HW_SCREEN_X_MAX
  213. #define C_Y_CLIPPING_MIN          0
  214. #define C_Y_CLIPPING_MAX   HW_SCREEN_Y_MAX
  215.  
  216. int C_volume_clipping(int *from,int *to,int *vertex,int dimension,int length);
  217.  
  218. int C_line_z_clipping(int **vertex1,int **vertex2,int dimension);
  219. int C_polygon_z_clipping(int *from,int *to,int dimension,int length);
  220.  
  221. int C_line_x_clipping(int **vertex1,int **vertex2,int dimension);
  222. int C_line_y_clipping(int **vertex1,int **vertex2,int dimension);
  223. int C_polygon_x_clipping(int *from,int *to,int dimension,int length);
  224.  
  225. #define M_AMBIENT              0x3          /* constant colour polygon */
  226. #define M_SHADED               0x4          /* Gouraud shaded polygon */
  227. #define M_TEXTURED             0x5          /* texture mapped polygon */
  228. #define M_POLYGON_LENGTH_LIMIT  50          /* length of tmp arrays */
  229.  
  230. #define M_SIZE_EDGE_ARRAY